
//
// Tokens.h
//
// This class splits the given string into tokens. Tokenisation
// is done depending on the token separators specified.
// Each token is converted into an Element. All the tokens are
// maintained in a list. An iterator can be used to browse
// through the list.
//

#ifndef _TOKENS_H_
#define	_TOKENS_H_

#include <iostream.h>
#include <string.h>

#include <Element.h>
#include <Node.h>

class Tokens {
private :
	Node* head;
	int num;

protected :
	Node* allocNode(Element elem);
	void deleteAll();
	int isSep(char* sep, char c);

public :
	Tokens();
	Tokens(char* input);
	Tokens(char* input, char* sep);

	void add(Element elem);

	void read(char* input);
	void read(char* input, char* sep);
	int ifExists(Element elem);
	int numElements() const;

	virtual ~Tokens();

	friend class TokensIter;

	friend ostream& operator<<(ostream& os, const Tokens& store);
};

//
// Token iterator
//

class TokensIter {
private :
	const Tokens* store;
	Node* curr;

public :
	TokensIter(const Tokens& tokens);
	TokensIter(const TokensIter& from);

	TokensIter& operator=(const TokensIter& from);

	void reset();
	int ok();

	void operator++();

	Node* current();
};

#endif // _TOKENS_H_

